<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机数</title>
</head>

<body>
    <script>
        function ranNum() {
            var a = Math.round(Math.random() * 5);
            document.getElementById("d1").innerHTML = a;
        }
    </script>
    <div id="d1"></div>
    <input type="button" value="随机数" onclick="ranNum()">
</body>

</html>